package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yanjing.domain.RiskInspection;
import com.ruoyi.yanjing.service.IRiskInspectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患排查记录Controller
 * 
 * @author whz
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/yanjing/inspection")
public class RiskInspectionController extends BaseController
{
    @Autowired
    private IRiskInspectionService riskInspectionService;

    /**
     * 查询隐患排查记录列表
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskInspection riskInspection)
    {
        startPage();
        List<RiskInspection> list = riskInspectionService.selectRiskInspectionList(riskInspection);
        return getDataTable(list);
    }

    /**
     * 导出隐患排查记录列表
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:export')")
    @Log(title = "隐患排查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskInspection riskInspection)
    {
        List<RiskInspection> list = riskInspectionService.selectRiskInspectionList(riskInspection);
        ExcelUtil<RiskInspection> util = new ExcelUtil<RiskInspection>(RiskInspection.class);
        util.exportExcel(response, list, "隐患排查记录数据");
    }

    /**
     * 获取隐患排查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(riskInspectionService.selectRiskInspectionById(id));
    }

    /**
     * 新增隐患排查记录
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:add')")
    @Log(title = "隐患排查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskInspection riskInspection)
    {
        return toAjax(riskInspectionService.insertRiskInspection(riskInspection));
    }

    /**
     * 修改隐患排查记录
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:edit')")
    @Log(title = "隐患排查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskInspection riskInspection)
    {
        return toAjax(riskInspectionService.updateRiskInspection(riskInspection));
    }

    /**
     * 删除隐患排查记录
     */
    @PreAuthorize("@ss.hasPermi('yanjing:inspection:remove')")
    @Log(title = "隐患排查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskInspectionService.deleteRiskInspectionByIds(ids));
    }
}
